package cn.gdcp.recycleviewtest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class AddActivity extends AppCompatActivity {
  EditText editName;
  EditText editAge;
  RadioButton m1;
  RadioButton m2;
  RadioButton m3;
  String name;
  String age;
  int imageId;
  Button summitBtn;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        initAddView();
        summitBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
           name=editName.getText().toString();
           age=editAge.getText().toString();
           if (m1.isChecked()){
               imageId=R.drawable.m1;
           }else if (m2.isChecked()){
              imageId=R.drawable.m2;
           }else {
               imageId=R.drawable.m3;
           }
                ReturnMessage(name,age,imageId);
            }
        });
    }

    private void ReturnMessage(String name, String age, int imageId) {
         Intent intent=new Intent();
         intent.putExtra("NAME",name);
         intent.putExtra("AGE",age);
         intent.putExtra("IMAGEID",imageId);
          setResult(2002,intent);
            finish();
    }


    private void initAddView() {
        editName=findViewById(R.id.add_name);
        editAge=findViewById(R.id.add_age);
        summitBtn=findViewById(R.id.summit_add_button);
         m1=findViewById(R.id.add_m1);
        m2=findViewById(R.id.add_m2);
        m3=findViewById(R.id.add_m3);
    }
}
